﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_Account_Modules_visa_Edit : System.Web.UI.UserControl
{

    private static int ID = 1;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack) {
            Item();
        }
    }


    private void Item() {
        try {
            ViewState["URLReferrer"] = Request.UrlReferrer.AbsoluteUri;
            ID = int.Parse(Request.Params["ID"].ToString());
            CMSDataContext db = new CMSDataContext();
            wVISA visa = db.wVISAs.Single(p => p.ID == ID);
            txtCODE.Text = ID.ToString();
            txtNAME.Text = visa.NAME;
        }
        catch { }
    }

    private Boolean UpdateData() {
        if (CMS.Check.CheckInt(txtCODE.Text))
        {
            ID = int.Parse(txtCODE.Text);
            CMSDataContext db = new CMSDataContext();
            wVISA visa = db.wVISAs.Single(p => p.ID == ID);
            visa.NAME = txtNAME.Text;
            db.SubmitChanges();
            return true;
        }
        return false;
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (UpdateData()){
            Response.Redirect(ViewState["URLReferrer"].ToString());
        }
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect(ViewState["URLReferrer"].ToString());
    }
}